package com.controller;

import com.entity.Patient;
import com.entity.Result;
import com.service.PatientService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@SuppressWarnings({"all"})
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/patient")
public class PatientController {

    @Resource
    private PatientService patientService;

    @PostMapping("/login")
    public Result login(Patient patient){
        try {
            return Result.success(patientService.login_patient(patient));
        } catch (Exception e) {
            return Result.error(patientService.login_patient(patient));
        }
    }

    @PostMapping("/register")
    public Result register(Patient patient) {
        try {
            return Result.success(patientService.register_patient(patient));
        } catch (Exception e) {
            return Result.error(patientService.register_patient(patient));
        }

    }

    @PostMapping("/hasRegister")
    public Result hasRegister(Patient patient) {
        try {
            return Result.success(patientService.hasRegister(patient.getPatientID()));
        } catch (Exception e) {
            return Result.error("hasRegister的未知错误");
        }
    }
}
